<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/6/22 0022
 * Time: 22:20
 */
namespace Home\Controller;
use Think\Controller;
use Think\Verify;

class FdController extends ComController{
    public function index(){

        $this->display();
    }

    public function yzm(){
        $config =    array(
            'fontSize'    =>    30,    // 验证码字体大小
            'length'      =>    4,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
            'useCurve'=>false
        );
        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }

    public function add(){
        $Hd=M("hd");
        $data['name']=I("post.name");
        $data['sex']=I("post.sex");
        $data['email']=I("post.email");
        $data['phone']=I("post.phone");
        $data['content']=I("post.content");
        $data['addtime']=time();
        $yzm=I("post.yzm");
        if($this->check($yzm)){
            if ($Hd->add($data)){
                $this->success("提交成功");
            }else{
                $this->error("提交失败");
            }
        }else{
            $this->error("验证码不正确");
        }
    }

    protected function check($code, $id = ''){
        $verify = new Verify();
        return $verify->check($code, $id);
    }
}